package com.zhuss.job.processor;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.zhuss.bean.bo.SearchKeyWordBo;
import com.zhuss.bean.bo.job.job.SearchJobBo;
import com.zhuss.bean.bo.job.job.wechat.ListJobBo;
import com.zhuss.bean.vo.DetailKeyWordVo;
import com.zhuss.bean.vo.job.job.DetailJobVo;
import com.zhuss.bean.vo.job.job.ListJobVo;
import com.zhuss.job.db.dao.ext.JobDao;
import com.zhuss.job.db.entity.Job;
import com.zhuss.common.PageVo;
import com.zhuss.exception.ExceptionCode;
import com.zhuss.exception.WpsException;


/**
 * 查询职位 processor
 * @Author: zhushanshuo
 * @Date: 2019/9/24 19:54
 */
@Component("jobRead")
public class JobRead {
	
	@Autowired
	private JobDao jobDao;
	
	/**
	 * 职位 
	 * @return
	 */
	public Object listJobId(Integer area) {
		List<Job> jobList = jobDao.listAll(area);
		List<Long> result = new ArrayList<>();
		transferListId(jobList, result);
		return result;
	}
	
	/**
	 * keyWord
	 * @param bo
	 * @return
	 */
	public PageVo<DetailKeyWordVo> keyWord(SearchKeyWordBo bo) {
		PageVo<DetailKeyWordVo> result = new PageVo<DetailKeyWordVo>();
		List<DetailKeyWordVo> list = new ArrayList<DetailKeyWordVo>();
		list = jobDao.keyWord(bo);
		Integer count = jobDao.countKeyWord(bo);
		result.setPageNum(bo.getPageNum());
		result.setPageSize(bo.getPageSize());
		result.setTotal(count);
		result.setItems(list);
		return result;
	}
	
	
	
	/**
	 * 职位列表
	 * @param bo
	 * @return
	 */
	public Object listJob(ListJobBo bo) {
		PageVo<DetailJobVo> result = new PageVo<DetailJobVo>();
		List<DetailJobVo> list = new ArrayList<DetailJobVo>();
		list = jobDao.listJob(bo);
		Integer count = jobDao.countJobList(bo);
		result.setPageNum(bo.getPageNum());
		result.setPageSize(bo.getPageSize());
		result.setTotal(count);
		result.setItems(list);
		return result;
	}
	
	private void transferListId(List<Job> jobList, List<Long> result) {
		for (Job item : jobList) {
			result.add(item.getJobId());
		}
	}

	/**
	 * 职位列表
	 * @param bo
	 * @return
	 */
	public Object list(SearchJobBo bo) {
		PageVo<ListJobVo> result = new PageVo<ListJobVo>();
        result.setPageNum(bo.getPageNum());
        result.setPageSize(bo.getPageSize());
        result.setItems(jobDao.list(bo));
        result.setTotal(jobDao.countList(bo));
		return result;
	}
	
	/**
	 * 职位详情
	 * @param jobId
	 * @return
	 * @throws WpsException
	 */
	public Object detail(Long jobId) throws WpsException {
		Object result = jobDao.detail(jobId);
		if (result == null) {
			throw new WpsException(ExceptionCode.数据不存在);
		}
		return result;
	}
	
	

}
